package com.kly.user.serviceImpl;


import com.fqgj.common.api.Response;
import com.kly.user.config.AppVersionInfoConfig;
import com.kly.user.dto.AppInfoDto;
import com.kly.user.enums.AppCode;
import com.kly.user.enums.ResultStatus;
import com.kly.user.service.AppOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("appOperateService")
public class AppOperateServiceImpl implements AppOperateService {

    @Autowired
    AppVersionInfoConfig appVersionInfoConfig;

    @Override
    public Response<AppInfoDto> upGradation(String appCode, Integer versionCode) {
        AppInfoDto appInfoDto=new AppInfoDto();
        Map<String, String> appConfig;
        AppCode appCode1 = AppCode.fromType(appCode);
        switch (appCode1) {
            case chat01:
                appConfig = appVersionInfoConfig.getChat01();
                break;
            default:
                return Response.error(ResultStatus.ILLEGAL_APPCODE);
        }
        appInfoDto.setAppCode(appCode);
        if (Integer.parseInt(appConfig.get("versionCode"))>versionCode){
            appInfoDto.setUpdateFlag(true);
            appInfoDto.setUpdateType(1);
            appInfoDto.setAppStoreUrl(appConfig.get("storeUrl"));
            appInfoDto.setOtherPlatforms(appConfig.get("otherPlatforms"));
            appInfoDto.setUpGradationDesc(appConfig.get("upGradationDesc"));
        }else {
            appInfoDto.setUpdateFlag(false);
        }
        return Response.ok(appInfoDto);
    }

}
